<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns=          "urn:jbpm.org:jpdl-3.2" 
           targetNamespace="urn:jbpm.org:jpdl-3.2" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified">

  <!--  PROCESS-DEFINITION -->
  <!--  ################## -->
  <xs:element name="process-definition">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="description" />
		<xs:element ref="node-group" />
        <xs:group   ref="node-elements"/>
      </xs:choice>
      <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>

  <!--  NODEGROUP -->
  <!--  ######## -->
  <xs:element name="node-group">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="1">
        <xs:group   ref="node-elements"/>
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>

  <!--  NODES -->
  <!--  ##### -->

  <xs:element name="decision">
    <xs:complexType>
      <xs:attribute name="name" type="xs:string" use="required"/>
      <xs:attribute name="priority" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
  	
  <xs:element name="practice-node">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="decision" />
        <xs:element ref="description" />
      </xs:choice>
      <xs:attribute name="name" type="xs:string" use="required"/>
	  <xs:attribute name="uriKey" type="xs:string" use="required"/>
	  <xs:attribute name="keyId" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="exam-node">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="decision" />
        <xs:element ref="description" />
      </xs:choice>
      <xs:attribute name="name" type="xs:string" use="required"/>
	  <xs:attribute name="uriKey" type="xs:string" use="required"/>
	  <xs:attribute name="keyId" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="script">
    <xs:complexType  mixed="true">
      <xs:sequence>
        <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" />
      <xs:attribute name="accept-propagated-events" type="booleanType" default="true" />
    </xs:complexType>
  </xs:element>

  <!-- TYPES AND GROUPS -->
  <!-- ################ -->

  <xs:element name="description" type="xs:string" />

  <xs:complexType name="delegation" mixed="true">
    <xs:sequence>
      <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="class" type="xs:string" />
    <xs:attribute name="config-type" default="field" type="xs:string" />
  </xs:complexType>

  <xs:simpleType name="configType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="field"/>
      <xs:enumeration value="bean"/>
      <xs:enumeration value="constructor"/>
      <xs:enumeration value="configuration-property"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="booleanType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="yes"/>
      <xs:enumeration value="no"/>
      <xs:enumeration value="true"/>
      <xs:enumeration value="false"/>
      <xs:enumeration value="on"/>
      <xs:enumeration value="off"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="priorityType">
    <xs:union>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="highest"/>
          <xs:enumeration value="high"/>
          <xs:enumeration value="normal"/>
          <xs:enumeration value="low"/>
          <xs:enumeration value="lowest"/>
        </xs:restriction>
      </xs:simpleType>
      <xs:simpleType>
        <xs:restriction base="xs:int"/>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>

  <xs:group name="node-elements">
    <xs:choice>
      <xs:element ref="decision"/>
      <xs:element ref="practice-node"/>
      <xs:element ref="exam-node"/>
    </xs:choice>
  </xs:group>
  
  <xs:group name="node-content-elements">
    <xs:choice>
      <xs:element ref="description" />
    </xs:choice>
  </xs:group>

  <xs:simpleType name="bindingType">
  	<xs:restriction base="xs:string">
  		<xs:enumeration value="late"></xs:enumeration>
  		<xs:enumeration value="early"></xs:enumeration>
  	</xs:restriction>
  </xs:simpleType>
</xs:schema>
